package org.kl.wx.entity;

import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.kl.bf.entity.AuditableEntity;
import org.kl.bf.entity.Excel;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 微信用户
 */
@Entity
@Table(name = "wx_user")
public class WxUser extends AuditableEntity {
	private static final long serialVersionUID = 1L;
	
	@Excel(exportName = "所属公共账号", exportProperty = "appName")
	private App app;
	@Excel(exportName = "所属组", exportProperty = "groupName")
	private Groups groups;
	
	@Excel(exportName = "是否订阅",exportConvertSign=1)
	private Integer subscribe;
	@Excel(exportName = "用户标识")
	private String openid;
	@Excel(exportName = "用户昵称")
	private String nickname;
	@Excel(exportName = "用户性别",exportConvertSign=1)
	private Integer userSex;
	@Excel(exportName = "用户所在城市")
	private String city;
	@Excel(exportName = "用户所在国家")
	private String country;
	@Excel(exportName = "用户所在省份")
	private String province;
	@Excel(exportName = "用户语言")
	private String language;
	@Excel(exportName = "用户头像Url")
	private String headimgurl;
	@Excel(exportName = "用户关注时间")
	private Timestamp subscribeTime;
	@Excel(exportName = "绑定平台账号 ")
	private String unionid;
	@Excel(exportName = "分组Id")
	private Integer originGroupId;
	
	public WxUser(){
	}
	
	public WxUser(String id){
		this.id = id;
	}
	
	@ManyToOne
	@JoinColumn(name = "app_id")
	public App getApp() {
		return app;
	}
	public void setApp(App app) {
		this.app = app;
	}
	
	@ManyToOne
	@JoinColumn(name = "wx_group_id")
	public Groups getGroups() {
		return groups;
	}
	public void setGroups(Groups groups) {
		this.groups = groups;
	}
	
	public Integer getSubscribe() {
		return subscribe;
	}
	public void setSubscribe(Integer subscribe) {
		this.subscribe = subscribe;
	}
	
	public String getOpenid() {
		return openid;
	}
	public void setOpenid(String openid) {
		this.openid = openid;
	}
	
	public String getNickname() {
		return nickname;
	}
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	
	public Integer getUserSex() {
		return userSex;
	}
	public void setUserSex(Integer userSex) {
		this.userSex = userSex;
	}
	
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
	}
	
	public String getProvince() {
		return province;
	}
	public void setProvince(String province) {
		this.province = province;
	}
	
	public String getLanguage() {
		return language;
	}
	public void setLanguage(String language) {
		this.language = language;
	}
	
	public String getHeadimgurl() {
		return headimgurl;
	}
	public void setHeadimgurl(String headimgurl) {
		this.headimgurl = headimgurl;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+08:00")
	public Timestamp getSubscribeTime() {
		return subscribeTime;
	}
	public void setSubscribeTime(Timestamp subscribeTime) {
		this.subscribeTime = subscribeTime;
	}
	
	public String getUnionid() {
		return unionid;
	}
	public void setUnionid(String unionid) {
		this.unionid = unionid;
	}
	
	public Integer getOriginGroupId() {
		return originGroupId;
	}
	public void setOriginGroupId(Integer originGroupId) {
		this.originGroupId = originGroupId;
	}	
	public String userSexConvert() {
		return userSex == 1 ? "男" : (userSex == 2?"女":"未知");
	}
	public String subscribeConvert() {
		return subscribe == 1 ? "是" : "否";
	}
}
